# -*- coding: utf-8 -*-

"""
@author: Laowang
@contact: QQ:1125564921
@Created on: 2022/7/7
@Remark: 
"""
import hprose


class FindFilter(object):
    """ 必须的基础类
        可以什么都不做
        也可以做钩子
    """

    def inputFilter(self, data, context):
        print("[inputFilter]", data, self, context)
        return data

    def outputFilter(self, data, context):
        # print("[outputFilter]", data, self, context)
        return data


class HproseProxy:

    def __init__(self, client=None) -> None:

        if not client:
            client = hprose.HttpClient('http://127.0.0.1:9898/')
        self._client = client
        self._client.filter = FindFilter()

    def __getattr__(self, name):

        def do_rpc(kw=None):
            handle = getattr(self._client, name)
            if kw is None:
                return handle()
            else:
                return handle(kw)
        return do_rpc


if __name__ == "__main__":
    hp = HproseProxy()
    print(hp.describe())
